import { ErrorBlock } from "antd-mobile";
import { createBrowserRouter, Link } from "react-router-dom";

const lazyHome = async () => {
  const { default: Home } = await import("../pages/tabs/Home");
  return {
    element: <Home />,
  };
};
let router = createBrowserRouter([
  {
    path: "/",
    async lazy() {
      const { default: App } = await import("../App");
      return {
        element: <App />,
      };
    },
    children: [
      {
        index: true,
        lazy: lazyHome,
      },
      {
        path: "home",
        lazy: lazyHome,
      },
      {
        path: "order",
        async lazy() {
          const { default: Order } = await import("../pages/tabs/Order");
          return {
            element: <Order />,
          };
        },
      },

      {
        path: "my",
        async lazy() {
          const { default: My } = await import("../pages/tabs/My");
          return {
            element: <My />,
          };
        },
      },
    ],
  },
  {
    path: "/chat",
    async lazy() {
      const { default: Chat } = await import("../pages/tabs/Chat");
      return {
        element: <Chat />,
      };
    },
  },
  {
    path: "/list",
    async lazy() {
      const { default: List,loader } = await import("../pages/list/index");
      return {
        element: <List />,
        loader
      };
    },
  },
  {
    path: "/detail/:id",
    async lazy() {
      const { default: Detail,loader } = await import("../pages/detail/index");
      return {
        element: <Detail />,
        loader
      };
    },
  },
   {
    path: "/city/:type",
    async lazy() {
      const { default: City,loader } = await import("../pages/city/index");
      return {
        element: <City />,
        loader
      };
    },
  },
  {
    path: "/login",
    async lazy() {
      const { default: Login, loader } = await import("../pages/auth/login");
      return {
        element: <Login />,
        loader,
      };
    },
  },
  {
    path: "*",
    element: (
      <ErrorBlock fullPage description={<Link to="/home">去首页</Link>} />
    ),
  },
]);
export default router;
